home *** CD-ROM | disk | FTP | other *** search
Text File | 1996-09-17 | 11.8 KB | 438 lines | [TEXT/MPS ] |
- //========================================================================================
- //
- // File: FWPictur.cpp
- // Release Version: $ ODF 2 $
- //
- // Copyright: (c) 1993 - 1996 by Apple Computer, Inc., all rights reserved.
- //
- //========================================================================================
-
- #include "FWOS.hpp"
-
- #ifndef FWPICTUR_H
- #include "FWPictur.h"
- #endif
-
- #ifndef SLGRGLOB_H
- #include "SLGrGlob.h"
- #endif
-
- #ifndef FWGRUTIL_H
- #include "FWGrUtil.h"
- #endif
-
- #ifndef FWGC_H
- #include "FWGC.h"
- #endif
-
- #ifndef FWODGEOM_H
- #include "FWODGeom.h"
- #endif
-
- // ----- OS Includes -----
-
- #ifndef FWRESACC_H
- #include "FWResAcc.h"
- #endif
-
- #ifndef FWRESSIN_H
- #include "FWResSin.h"
- #endif
-
- #ifndef FWACQUIR_H
- #include "FWAcquir.h"
- #endif
-
- // ----- Foundation Includes -----
-
- #ifndef FWSOMENV_H
- #include "FWSOMEnv.h"
- #endif
-
- #ifndef FWSTREAM_H
- #include "FWStream.h"
- #endif
-
- #ifndef FWDEBUG_H
- #include "FWDebug.h"
- #endif
-
- #ifndef FWSTRMRW_H
- #include "FWStrmRW.h"
- #endif
-
- #ifndef FWMEMMGR_H
- #include "FWMemMgr.h"
- #endif
-
- // ----- OpenDoc Includes -----
-
- #ifndef SOM_ODCanvas_xh
- #include <Canvas.xh>
- #endif
-
- #ifndef SOM_ODShape_xh
- #include <Shape.xh>
- #endif
-
- #ifndef SOM_ODTransform_xh
- #include <Trnsform.xh>
- #endif
-
- // ----- Macintosh Includes -----
-
- #if defined(FW_BUILD_MAC) && !defined(__RESOURCES__)
- #include <Resources.h>
- #endif
-
- //========================================================================================
- // RunTime Info
- //========================================================================================
-
- #ifdef FW_BUILD_MAC
- #pragma segment FWGraphics_Picture
- #endif
-
- //========================================================================================
- // Template instantiation
- //========================================================================================
-
- #include "FWGrRef.tpp"
-
- FW_DEFINE_AUTO_TEMPLATE(FW_TGrRefPtr, FW_HPicture)
-
- #ifdef FW_USE_TEMPLATE_PRAGMAS
-
- #pragma template_access public
- #pragma template FW_TGrRefPtr<FW_HPicture>
-
- #else
-
- template class FW_TGrRefPtr<FW_HPicture>;
-
- #endif
-
- //========================================================================================
- // class FW_CPicture
- //========================================================================================
-
- FW_DEFINE_AUTO(FW_CPicture)
-
- //----------------------------------------------------------------------------------------
- // FW_PrivAcquireGrRep
- //----------------------------------------------------------------------------------------
-
- void FW_PrivAcquireGrRep(FW_HPicture rep)
- {
- if (rep != 0)
- FW_PrivPicture_Acquire(rep);
- }
-
- //----------------------------------------------------------------------------------------
- // FW_PrivReleaseGrRep
- //----------------------------------------------------------------------------------------
-
- void FW_PrivReleaseGrRep(FW_HPicture rep)
- {
- if (rep != 0)
- FW_PrivPicture_Release(rep);
- }
-
- //----------------------------------------------------------------------------------------
- // FW_CPicture::FW_CPicture
- //----------------------------------------------------------------------------------------
-
- FW_CPicture::FW_CPicture()
- {
- FW_END_CONSTRUCTOR
- }
-
- //----------------------------------------------------------------------------------------
- // FW_CPicture::FW_CPicture
- //----------------------------------------------------------------------------------------
-
- FW_CPicture::FW_CPicture(FW_PlatformPict platformPict)
- {
- FW_PlatformError error;
- FW_HPicture rep = FW_PrivPicture_CreateFromPlatformPict(platformPict, &error);
- FW_FailOnError(error);
- SetRep(rep);
- FW_END_CONSTRUCTOR
- }
-
- //----------------------------------------------------------------------------------------
- // FW_CPicture::FW_CPicture
- //----------------------------------------------------------------------------------------
-
- FW_CPicture::FW_CPicture(FW_PResourceFile& resourceFile, FW_ResourceID resourceID)
- {
- FW_PlatformError error;
- FW_HPicture rep = FW_PrivPicture_CreateFromResource(resourceFile, resourceID, &error);
- FW_FailOnError(error);
- SetRep(rep);
- FW_END_CONSTRUCTOR
- }
-
- //----------------------------------------------------------------------------------------
- // FW_CPicture::FW_CPicture
- //----------------------------------------------------------------------------------------
-
- FW_CPicture::FW_CPicture(const FW_CPicture& other) :
- FW_TGrRefPtr<FW_HPicture>(other)
- {
- FW_END_CONSTRUCTOR
- }
-
- //----------------------------------------------------------------------------------------
- // FW_CPicture::FW_CPicture
- //----------------------------------------------------------------------------------------
-
- FW_CPicture::FW_CPicture(FW_CReadableStream& stream)
- {
- FW_PlatformError error;
- FW_HPicture rep = FW_PrivPicture_Read(stream, &error);
- FW_FailOnError(error);
- SetRep(rep);
- FW_END_CONSTRUCTOR
- }
-
- //----------------------------------------------------------------------------------------
- // FW_CPicture::~FW_CPicture
- //----------------------------------------------------------------------------------------
-
- FW_CPicture::~FW_CPicture()
- {
- FW_START_DESTRUCTOR
- }
-
- //----------------------------------------------------------------------------------------
- // FW_CPicture::operator=
- //----------------------------------------------------------------------------------------
-
- FW_CPicture& FW_CPicture::operator=(const FW_CPicture& other)
- {
- FW_TGrRefPtr<FW_HPicture>::operator=(other);
- return *this;
- }
-
- //----------------------------------------------------------------------------------------
- // FW_CPicture::Copy
- //----------------------------------------------------------------------------------------
-
- FW_CPicture FW_CPicture::Copy() const
- {
- FW_PlatformError error;
- FW_HPicture rep = FW_PrivPicture_Copy(fRep, &error);
- FW_FailOnError(error);
-
- FW_CPicture picture;
- picture.SetRep(rep);
- return picture;
- }
-
- //----------------------------------------------------------------------------------------
- // FW_CPicture::Copy
- //----------------------------------------------------------------------------------------
-
- void FW_CPicture::GetPictBounds(FW_SGraphicContext& gc, FW_SRect& bounds) const
- {
- FW_PrivPicture_GetPictBoundsGC(gc.fEnvironment, fRep, gc, bounds);
- FW_FailOnEvError(gc.fEnvironment);
- }
-
- //----------------------------------------------------------------------------------------
- // FW_CPicture::SetPlatformPict
- //----------------------------------------------------------------------------------------
-
- void FW_CPicture::SetPlatformPict(FW_PlatformPict newPict)
- {
- if (!fRep)
- {
- FW_PlatformError error;
- FW_HPicture rep = FW_PrivPicture_CreateFromPlatformPict(newPict, &error);
- FW_FailOnError(error);
- SetRep(rep);
- }
- else
- FW_PrivPicture_SetPlatformPict(fRep, newPict);
- }
-
- //----------------------------------------------------------------------------------------
- // FW_CPicture::AdoptPlatformPict
- //----------------------------------------------------------------------------------------
-
- void FW_CPicture::AdoptPlatformPict(FW_PlatformPict newPict)
- {
- if (!fRep)
- {
- FW_PlatformError error;
- FW_HPicture rep = FW_PrivPicture_CreateFromPlatformPict(newPict, &error);
- FW_FailOnError(error);
- SetRep(rep);
- }
-
- // call adopt whether or not we originally had a rep. this will
- // cause the adoption of ownership
- FW_PrivPicture_AdoptPlatformPict(fRep, newPict);
- }
-
-
- //========================================================================================
- // Stream I/O
- //========================================================================================
-
- //----------------------------------------------------------------------------------------
- // operator>>
- //----------------------------------------------------------------------------------------
-
- FW_CReadableStream& operator>>(FW_CReadableStream& stream, FW_CPicture& picture)
- {
- FW_PlatformError error;
- FW_HPicture rep = FW_PrivPicture_Read(stream, &error);
- FW_FailOnError(error);
- picture.SetRep(rep);
- return stream;
- }
-
- //----------------------------------------------------------------------------------------
- // operator<<
- //----------------------------------------------------------------------------------------
-
- FW_CWritableStream& operator<<(FW_CWritableStream& stream, const FW_CPicture& picture)
- {
- FW_PlatformError error;
- FW_PrivPicture_Write(picture.fRep, stream, &error);
- FW_FailOnError(error);
- return stream;
- }
-
- //========================================================================================
- // class FW_CPictureContext
- //========================================================================================
-
- FW_DEFINE_AUTO(FW_CPictureContext)
-
- //----------------------------------------------------------------------------------------
- // FW_CPictureContext::FW_CPictureContext
- //----------------------------------------------------------------------------------------
-
- FW_CPictureContext::FW_CPictureContext(Environment* ev,
- FW_CPicture& picture,
- FW_Fixed xSize,
- FW_Fixed ySize) :
- FW_CGraphicContext(ev),
- #ifdef FW_BUILD_MAC
- fMacPictHandle(NULL),
- #endif
- fPicture(picture),
- fGraphicDevice(NULL)
- {
- ODPlatformCanvas platformCanvas;
-
- FW_CRect clipRect;
-
- #ifdef FW_BUILD_MAC
- platformCanvas = FW_gScratchPort;
- clipRect.Set(FW_IntToFixed(0), FW_IntToFixed(0), xSize, ySize);
- #endif
-
- #ifdef FW_BUILD_WIN
- HDC hDCRef = ::GetDC(NULL);
-
- int xRes = ::GetDeviceCaps(hDCRef, LOGPIXELSX);
- int yRes = ::GetDeviceCaps(hDCRef, LOGPIXELSY);
-
- int xDevMM = ::GetDeviceCaps(hDCRef, HORZSIZE);
- int yDevMM = ::GetDeviceCaps(hDCRef, VERTSIZE);
- int xDevPix = ::GetDeviceCaps(hDCRef, HORZRES);
- int yDevPix = ::GetDeviceCaps(hDCRef, VERTRES);
-
- // The size comes in at 72dpi: convert to HiMetric units (0.01 mm)
- FW_CPlatformRect boundsMM(0, 0, FW_FixedToInt(xSize) * 2540 / 72, FW_FixedToInt(ySize) * 2540 / 72);
-
- platformCanvas = ::CreateEnhMetaFile(hDCRef, NULL, &boundsMM, NULL);
-
- // Convert size to pixels, for use in the coordinate system
- int xSizePix =
- FW_FixedToInt(FW_WideMultiply(xSize, FW_IntToFixed(xRes)) / FW_kFixed72);
-
- int ySizePix =
- FW_FixedToInt(FW_WideMultiply(ySize, FW_IntToFixed(yRes)) / FW_kFixed72);
-
- int xDraw = (254 * xSizePix * xDevPix) / (100 * xDevMM);
- int yDraw = (254 * ySizePix * yDevPix) / (100 * yDevMM);
-
- clipRect.SetInt(0, 0, xDraw, yDraw);
-
- ::ReleaseDC(NULL, hDCRef);
- #endif
-
- fGraphicDevice = FW_PrivGDev_CreateFromPlatformCanvas(ev, platformCanvas);
- FW_FailOnEvError(ev);
-
- #ifdef FW_BUILD_WIN
- // Set the resolution: (xSize, ySize) should map to (xDraw, yDraw)
- FW_PrivGDev_SetResolution(fGraphicDevice,
- FW_IntToFixed(boundsMM.right) / FW_IntToFixed(xDraw),
- FW_IntToFixed(boundsMM.bottom) / FW_IntToFixed(yDraw)
- );
- #endif
-
- FW_CAcquiredODShape aqClipShape = ::FW_NewODShape(ev, clipRect);
-
- InitGraphicContext(fGraphicDevice,
- NULL,
- aqClipShape);
-
- #ifdef FW_BUILD_MAC
- FW_CPlatformRect plfmBounds(0, 0, FW_FixedToInt(xSize), FW_FixedToInt(ySize));
-
- ::PortSize(plfmBounds.right, plfmBounds.bottom);
- fMacPictHandle = ::OpenPicture(&plfmBounds);
- #endif
-
- FW_END_CONSTRUCTOR
- }
-
- //----------------------------------------------------------------------------------------
- // FW_CPictureContext::~FW_CPictureContext
- //----------------------------------------------------------------------------------------
-
- FW_CPictureContext::~FW_CPictureContext()
- {
- FW_START_DESTRUCTOR
-
- FW_PlatformPict newPict;
-
- #ifdef FW_BUILD_MAC
- ::ClosePicture();
- newPict = fMacPictHandle;
- #endif
-
- #ifdef FW_BUILD_WIN
- HDC hDC = FW_PrivGDev_GetPlatformCanvas(fGraphicDevice);
- #endif
-
- // ----- Terminate the superclass
- TerminateGraphicContext();
-
- #ifdef FW_BUILD_WIN
- newPict = ::CloseEnhMetaFile(hDC);
- #endif
-
- // ----- Delete the device
- FW_PrivGDev_Release(fGraphicDevice);
-
- // ----- Store the result in the picture
- fPicture.AdoptPlatformPict(newPict);
- }
-
- //----------------------------------------------------------------------------------------
- // FW_CPictureContext::Reset
- //----------------------------------------------------------------------------------------
-
- void FW_CPictureContext::Reset()
- {
- // Nothing to do [HLX] Am i sure ?
- }
-